Skip to content

SDKS-4815: Fix journey client middleware#544

Open
ancheetah wants to merge 2 commits intomainfrom
SDKS-4815-fix-middleware
Open

SDKS-4815: Fix journey client middleware#544
ancheetah wants to merge 2 commits intomainfrom
SDKS-4815-fix-middleware

Conversation

@ancheetah
Copy link
Collaborator

@ancheetah ancheetah commented Mar 3, 2026

JIRA Ticket

https://pingidentity.atlassian.net/browse/SDKS-4815

Description

  • Updates middleware e2e test for journey client
  • Removes duplicate middleware config in serverConfig
  • Adds support for typed (ActionType) middleware

Summary by CodeRabbit

  • New Features

    • Added typed middleware support with explicit action type constraints for journey operations
    • Implemented Accept-Language header configuration that automatically sets language preferences per journey action
  • Bug Fixes

    • Removed duplicate middleware configuration from initialization
  • Chores

    • Updated middleware configuration parameters and type exports to support stronger typing

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 29220e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@forgerock/journey-client Patch
@forgerock/davinci-client Patch
@forgerock/device-client Patch
@forgerock/oidc-client Patch
@forgerock/protect Patch
@forgerock/sdk-types Patch
@forgerock/sdk-utilities Patch
@forgerock/iframe-manager Patch
@forgerock/sdk-logger Patch
@forgerock/sdk-oidc Patch
@forgerock/sdk-request-middleware Patch
@forgerock/storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

This PR introduces generic type parameters to RequestMiddleware, constraining middleware functions to specific journey action types, removes the middleware field from configuration types, and updates tests to validate typed middleware behavior with Accept-Language header assignments.

Changes

Cohort / File(s) Summary
Changeset & Version
.changeset/hip-lands-call.md
Patch version bump for @forgerock/journey-client documenting removal of duplicate middleware configuration and addition of typed middleware support.
Client Store Typing
packages/journey-client/src/lib/client.store.ts, packages/journey-client/src/lib/client.store.utils.ts
Made journey functions generic over ActionType, updated RequestMiddleware parameter types to be constrained by specific action types, and removed middleware field from config dispatch.
Config Type Removal
packages/journey-client/src/lib/config.types.ts, packages/journey-client/src/lib/config.slice.ts
Removed middleware field and RequestMiddleware type from JourneyClientConfig, InternalJourneyClientConfig, and ResolvedConfig; removed RequestMiddleware import and assignment from reducer.
Public API Exports
packages/journey-client/src/types.ts
Added ActionTypes to public type exports alongside RequestMiddleware from @forgerock/sdk-request-middleware.
Test Updates
packages/journey-client/src/lib/config.slice.test.ts
Removed middleware import and test suite validating middleware storage in configSlice state.
E2E & Request Middleware Tests
e2e/journey-app/main.ts, e2e/journey-suites/src/request-middleware.test.ts
Introduced strongly-typed RequestMiddleware array with action type union; added Accept-Language header population per action type; updated test assertions to validate middleware headers and Accept-Language values instead of checking raw middleware entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • cerebrl
  • ryanbas21

Poem

🐰 Typed middleware hops with grace,
Each action finds its proper place,
Accept-Language now speaks clear,
No duplicate configs here!
Types constrain what flows through—
Journey's path both strong and true.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing journey client middleware by adding type support and removing duplicates.
Description check ✅ Passed The description covers all required template sections with appropriate detail about JIRA ticket, changes made, and the changeset addition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SDKS-4815-fix-middleware

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Mar 3, 2026

View your CI Pipeline Execution ↗ for commit 29220e2

Command Status Duration Result
nx run-many -t build --no-agents ✅ Succeeded <1s View ↗
nx affected -t build lint test typecheck e2e-ci ✅ Succeeded 5m 31s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-03 18:18:36 UTC

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
e2e/journey-app/main.ts (2)

44-54: Same optional chaining inconsistency.

Line 48 uses req.headers.append() without optional chaining while line 49 uses req.headers?.set(). Apply the same consistency fix here.

♻️ Proposed fix
       case 'JOURNEY_TERMINATE':
         req.url.searchParams.set('end-session-middleware', 'end-session');
         req.headers.append('x-end-session-middleware', 'end-session');
-        req.headers?.set('Accept-Language', 'zz-ZZ');
+        req.headers.set('Accept-Language', 'zz-ZZ');
         break;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/journey-app/main.ts` around lines 44 - 54, The middleware handling the
'JOURNEY_TERMINATE' action mixes direct and optional-chained header access
(req.headers.append(...) vs req.headers?.set(...)); make them consistent by
using the same presence-guard approach for headers in that switch case — update
the block handling 'JOURNEY_TERMINATE' to call the same method access style
(either both optional-chained or both direct) on req.headers (e.g., change
req.headers.append to req.headers?.append or change req.headers?.set to
req.headers.set) so both header manipulations use the identical pattern.

29-42: Inconsistent optional chaining on req.headers.

Lines 32-33 and 37-38 use req.headers.append() without optional chaining, while lines 34 and 39 use req.headers?.set() with optional chaining. This inconsistency suggests either the optional chaining is unnecessary or the non-optional calls could fail if headers were ever undefined.

♻️ Proposed fix for consistency
       case 'JOURNEY_START':
         req.url.searchParams.set('start-authenticate-middleware', 'start-authentication');
         req.headers.append('x-start-authenticate-middleware', 'start-authentication');
-        req.headers?.set('Accept-Language', 'xx-XX');
+        req.headers.set('Accept-Language', 'xx-XX');
         break;
       case 'JOURNEY_NEXT':
         req.url.searchParams.set('authenticate-middleware', 'authentication');
         req.headers.append('x-authenticate-middleware', 'authentication');
-        req.headers?.set('Accept-Language', 'yy-YY');
+        req.headers.set('Accept-Language', 'yy-YY');
         break;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/journey-app/main.ts` around lines 29 - 42, The code inconsistently uses
optional chaining on req.headers (mixing req.headers.append(...) and
req.headers?.set(...)) inside the middleware handling action.type
'JOURNEY_START' and 'JOURNEY_NEXT'; make it consistent by treating req.headers
as non-null (remove the ?. calls) or defensively guarding all header operations
with optional chaining or a null check. Update the four header operations
(setting 'x-start-authenticate-middleware', 'x-authenticate-middleware', and
'Accept-Language') so they all use the same approach (either
req.headers.append(...) / req.headers.set(...) everywhere or check if
req.headers before calling append/set) to prevent runtime errors and keep
behavior predictable.
e2e/journey-suites/src/request-middleware.test.ts (1)

68-75: Redundant assertions for Accept-Language.

Lines 69-71 checking .not.toContain('en-US') are redundant since lines 73-75 assert the exact expected values. If xx-XX, yy-YY, and zz-ZZ are correct, they inherently don't contain en-US.

Consider removing lines 69-71 to reduce test verbosity.

♻️ Proposed simplification
   // Check that Accept-Language header was modified from default en-US locale and set to correct value in each middleware
-  expect(startHeader?.get('Accept-Language')).not.toContain('en-US');
-  expect(nextHeader?.get('Accept-Language')).not.toContain('en-US');
-  expect(endHeader?.get('Accept-Language')).not.toContain('en-US');
-
   expect(startHeader?.get('Accept-Language')).toBe('xx-XX');
   expect(nextHeader?.get('Accept-Language')).toBe('yy-YY');
   expect(endHeader?.get('Accept-Language')).toBe('zz-ZZ');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/journey-suites/src/request-middleware.test.ts` around lines 68 - 75,
Remove the redundant "not.toContain('en-US')" assertions for Accept-Language by
deleting the three checks that reference startHeader?.get('Accept-Language'),
nextHeader?.get('Accept-Language'), and endHeader?.get('Accept-Language') which
assert they do not contain 'en-US'; keep the existing exact-value assertions
that expect 'xx-XX', 'yy-YY', and 'zz-ZZ' respectively so the test remains
concise and still validates the header transformations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@e2e/journey-app/main.ts`:
- Around line 44-54: The middleware handling the 'JOURNEY_TERMINATE' action
mixes direct and optional-chained header access (req.headers.append(...) vs
req.headers?.set(...)); make them consistent by using the same presence-guard
approach for headers in that switch case — update the block handling
'JOURNEY_TERMINATE' to call the same method access style (either both
optional-chained or both direct) on req.headers (e.g., change req.headers.append
to req.headers?.append or change req.headers?.set to req.headers.set) so both
header manipulations use the identical pattern.
- Around line 29-42: The code inconsistently uses optional chaining on
req.headers (mixing req.headers.append(...) and req.headers?.set(...)) inside
the middleware handling action.type 'JOURNEY_START' and 'JOURNEY_NEXT'; make it
consistent by treating req.headers as non-null (remove the ?. calls) or
defensively guarding all header operations with optional chaining or a null
check. Update the four header operations (setting
'x-start-authenticate-middleware', 'x-authenticate-middleware', and
'Accept-Language') so they all use the same approach (either
req.headers.append(...) / req.headers.set(...) everywhere or check if
req.headers before calling append/set) to prevent runtime errors and keep
behavior predictable.

In `@e2e/journey-suites/src/request-middleware.test.ts`:
- Around line 68-75: Remove the redundant "not.toContain('en-US')" assertions
for Accept-Language by deleting the three checks that reference
startHeader?.get('Accept-Language'), nextHeader?.get('Accept-Language'), and
endHeader?.get('Accept-Language') which assert they do not contain 'en-US'; keep
the existing exact-value assertions that expect 'xx-XX', 'yy-YY', and 'zz-ZZ'
respectively so the test remains concise and still validates the header
transformations.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ea79b4 and 29220e2.

📒 Files selected for processing (9)
  • .changeset/hip-lands-call.md
  • e2e/journey-app/main.ts
  • e2e/journey-suites/src/request-middleware.test.ts
  • packages/journey-client/src/lib/client.store.ts
  • packages/journey-client/src/lib/client.store.utils.ts
  • packages/journey-client/src/lib/config.slice.test.ts
  • packages/journey-client/src/lib/config.slice.ts
  • packages/journey-client/src/lib/config.types.ts
  • packages/journey-client/src/types.ts
💤 Files with no reviewable changes (3)
  • packages/journey-client/src/lib/config.types.ts
  • packages/journey-client/src/lib/config.slice.ts
  • packages/journey-client/src/lib/config.slice.test.ts

@ancheetah ancheetah requested review from cerebrl and ryanbas21 March 3, 2026 18:18
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 3, 2026

Open in StackBlitz

@forgerock/davinci-client

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/davinci-client@544

@forgerock/device-client

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/device-client@544

@forgerock/journey-client

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/journey-client@544

@forgerock/oidc-client

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/oidc-client@544

@forgerock/protect

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/protect@544

@forgerock/sdk-types

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/sdk-types@544

@forgerock/sdk-utilities

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/sdk-utilities@544

@forgerock/iframe-manager

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/iframe-manager@544

@forgerock/sdk-logger

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/sdk-logger@544

@forgerock/sdk-oidc

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/sdk-oidc@544

@forgerock/sdk-request-middleware

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/sdk-request-middleware@544

@forgerock/storage

pnpm add https://pkg.pr.new/ForgeRock/ping-javascript-sdk/@forgerock/storage@544

commit: 29220e2

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Deployed 3111ec7 to https://ForgeRock.github.io/ping-javascript-sdk/pr-544/3111ec7b3412799a887c37f590217b0959d0a9a2 branch gh-pages in ForgeRock/ping-javascript-sdk

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

📦 Bundle Size Analysis

📦 Bundle Size Analysis

🆕 New Packages

🆕 @forgerock/journey-client - 87.3 KB (new)
🆕 @forgerock/journey-client - 0.0 KB (new)

➖ No Changes

@forgerock/sdk-logger - 1.6 KB
@forgerock/sdk-request-middleware - 4.5 KB
@forgerock/iframe-manager - 2.4 KB
@forgerock/sdk-oidc - 4.8 KB
@forgerock/storage - 1.5 KB
@forgerock/sdk-types - 7.9 KB
@forgerock/protect - 150.1 KB
@forgerock/device-client - 9.2 KB
@forgerock/davinci-client - 41.3 KB
@forgerock/sdk-utilities - 11.2 KB
@forgerock/oidc-client - 24.9 KB


13 packages analyzed • Baseline from latest main build

Legend

🆕 New package
🔺 Size increased
🔻 Size decreased
➖ No change

ℹ️ How bundle sizes are calculated
  • Current Size: Total gzipped size of all files in the package's dist directory
  • Baseline: Comparison against the latest build from the main branch
  • Files included: All build outputs except source maps and TypeScript build cache
  • Exclusions: .map, .tsbuildinfo, and .d.ts.map files

🔄 Updated automatically on each push to this PR

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 14.74%. Comparing base (b89ad58) to head (29220e2).
⚠️ Report is 55 commits behind head on main.

❌ Your project status has failed because the head coverage (14.74%) is below the target coverage (40.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #544      +/-   ##
==========================================
- Coverage   18.79%   14.74%   -4.06%     
==========================================
  Files         140      153      +13     
  Lines       27640    26262    -1378     
  Branches      980     1055      +75     
==========================================
- Hits         5195     3872    -1323     
+ Misses      22445    22390      -55     
Files with missing lines Coverage Δ
packages/journey-client/src/lib/client.store.ts 73.37% <100.00%> (-19.41%) ⬇️
...kages/journey-client/src/lib/client.store.utils.ts 100.00% <100.00%> (ø)
packages/journey-client/src/lib/config.slice.ts 100.00% <ø> (ø)
packages/journey-client/src/lib/config.types.ts 100.00% <ø> (ø)
packages/journey-client/src/types.ts 3.33% <ø> (+3.33%) ⬆️

... and 45 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants